<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js实现颜色选取器</title>

  <script src="./color-picker.js"></script>

  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .picker {
      width: 300px;
      height: 20px;
      cursor: pointer;
      position: absolute;
      left: 40px;
      top: 40px;
      color: #fff;
    }
  </style>

</head>
<body>

<div class="picker" id="color-picker">请选择颜色</div>


<script type="text/javascript">
  Colorpicker.create({
    el: "color-picker", //元素id
    color: "#000fff", //默认颜色
    change: function (elem, hex) {
      //选中颜色发生改变时事件
      elem.style.backgroundColor = hex;
    }
  })
</script>
</body>
</html>

